package com.zangbuge.hellonacos.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.function.RequestPredicates;
import org.springframework.web.servlet.function.RouterFunction;
import org.springframework.web.servlet.function.RouterFunctions;
import org.springframework.web.servlet.function.ServerResponse;
import reactor.core.publisher.Mono;

import java.time.Duration;

/**
 * 路由的方式使用
 *
 * @author Li Huiming
 * @date 2022/4/8
 */
@Configuration
public class WebFluxConfig {

    @Bean
    public RouterFunction<ServerResponse> webFlux() {
        return RouterFunctions.route(RequestPredicates.GET("/webFlux"), request -> {
            Mono<String> str = Mono.just("Hello World").delayElement(Duration.ofMillis(10));
            return ServerResponse.ok().body(str);
        });
    }

}
